<?php

namespace app\api\controller;

use app\admin\model\Order;
use app\common\controller\Api;

/**
 * 首页接口
 */
class Course extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     *
     * 课程列表
     *
     */
    public function index()
    {
        $list = \app\admin\model\Course::where(["switch"=>1])->select();
        $this->success("获取课程列表",$list);
    }

    public function order(){
        $course_id = $this->request->param("id");
        //根据id查询商品的价格以及生成订单号
        $product = \app\admin\model\Course::where(["id"=>$course_id])->find();
        if(empty($product)&&$product["switch"]!=1){
            $this->error("商品暂停售卖");
        }
        //生成订单号
        $orderNo = date('YmdHis').substr(microtime(), 2, 5) . mt_rand(10000,99999);
        if(!empty($unique)) $orderNo = $orderNo.$unique;
        //创建订单
        Order::create([
            'order_sn'=>$orderNo,
            'product_id'=>$course_id,
            'cost'=>$product['origin_price'],
            'price'=>$product['prese_price'],
        ]);
        $this->success("创建订单完毕");
    }

    //调用支付
    public function alipay(){
        $id = $this->request->param("id");
        $order = $this->request->param("order_sn");
        $ls_pay = new \LeshuaHelper('0114517526', '2AA09E29FB214E7333483373F65687AE');
        var_dump($ls_pay);exit();
    }
}
